package com.bjqg.bjqg01.bjqg.activity.longrange.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.bjqg.bjqg01.bjqg.R;
import com.bjqg.bjqg01.bjqg.activity.BaseActivity;
import com.bjqg.bjqg01.bjqg.activity.address.activity.AddressManagerActivity;
import com.bjqg.bjqg01.bjqg.activity.longrange.adapter.ImageItem;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.AddressEventBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.FsBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.MaterialBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.MultipleBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.PipeBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.dialog.BottomMenuDialog;
import com.bjqg.bjqg01.bjqg.activity.longrange.dialog.JcDialog;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.CydwBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.CyrBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.GcmcBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.JzdwBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.JzrBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.SgbwBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.WtdwBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.WtrBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.WtrPhoneBeanUtils;
import com.bjqg.bjqg01.bjqg.ui.pickview.OptionsPickerView;
import com.bjqg.bjqg01.bjqg.ui.pickview.listener.CustomListener;
import com.bjqg.bjqg01.bjqg.utils.Bimp;
import com.bjqg.bjqg01.bjqg.utils.BitmapUtils;
import com.bjqg.bjqg01.bjqg.utils.GreendaoUtils;
import com.jph.takephoto.app.TakePhoto;
import com.jph.takephoto.app.TakePhotoActivity;
import com.jph.takephoto.compress.CompressConfig;
import com.jph.takephoto.model.TImage;
import com.jph.takephoto.model.TResult;
import com.jph.takephoto.model.TakePhotoOptions;
import com.zhy.autolayout.AutoLinearLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by bjqg01 on 2018/9/7.
 */

public class PipeActivity extends TakePhotoActivity {

    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.tv_top_title_drawer)
    TextView tvTopTitleDrawer;
    @BindView(R.id.tv_search_top_drawer)
    TextView tvSearchTopDrawer;
    @BindView(R.id.tv_jllb)
    TextView tvJllb;
    @BindView(R.id.commissioned_et_wtdw)
    AutoCompleteTextView commissionedEtWtdw;
    @BindView(R.id.et_wtr)
    AutoCompleteTextView etWtr;
    @BindView(R.id.et_wtrdh)
    AutoCompleteTextView etWtrdh;
    @BindView(R.id.commissioned_et_gcmc)
    AutoCompleteTextView commissionedEtGcmc;
    @BindView(R.id.et_sgbw)
    AutoCompleteTextView etSgbw;
    @BindView(R.id.et_slgc_scdw)
    EditText etSlgcScdw;
    @BindView(R.id.et_slgc_cpmc)
    EditText etSlgcCpmc;
    @BindView(R.id.et_slgc_jyyj)
    EditText etSlgcJyyj;
    @BindView(R.id.et_slgc_ggxh)
    EditText etSlgcGgxh;
    @BindView(R.id.et_slgc_dbpl)
    EditText etSlgcDbpl;
    @BindView(R.id.et_slgc_zlzms)
    EditText etSlgcZlzms;
    @BindView(R.id.et_slgc_sb)
    EditText etSlgcSb;
    @BindView(R.id.et_slgc_lysl)
    EditText etSlgcLysl;
    @BindView(R.id.et_slgc_jcxm)
    TextView etSlgcJcxm;
    @BindView(R.id.ll_slgc_father)
    AutoLinearLayout llSlgcFather;
    @BindView(R.id.et_slgj_ggxh)
    EditText etSlgjGgxh;
    @BindView(R.id.et_slgj_sjmc)
    EditText etSlgjSjmc;
    @BindView(R.id.et_slgj_cjmc)
    EditText etSlgjCjmc;
    @BindView(R.id.et_slgj_sb)
    EditText etSlgjSb;
    @BindView(R.id.et_slgj_zlzmsh)
    EditText etSlgjZlzmsh;
    @BindView(R.id.et_slgj_yjbz)
    EditText etSlgjYjbz;
    @BindView(R.id.et_slgj_dbpl)
    EditText etSlgjDbpl;
    @BindView(R.id.et_slgj_lysl)
    EditText etSlgjLysl;
    @BindView(R.id.et_slgj_jcxm)
    TextView etSlgjJcxm;
    @BindView(R.id.ll_slgj_father)
    AutoLinearLayout llSlgjFather;
    @BindView(R.id.et_fsjcty_zj)
    TextView etFsjctyZj;

    @BindView(R.id.et_cydw)
    AutoCompleteTextView etCydw;

    @BindView(R.id.et_cyr)
    AutoCompleteTextView etCyr;

    @BindView(R.id.et_jzdw)
    AutoCompleteTextView etJzdw;
    @BindView(R.id.et_jzr)
    AutoCompleteTextView etJzr;

    @BindView(R.id.ll_jzqy)
    AutoLinearLayout llJzqy;
    @BindView(R.id.et_bz)
    EditText etBz;
    @BindView(R.id.rb_zq)
    RadioButton rbZq;
    @BindView(R.id.rb_yj)
    RadioButton rbYj;
    @BindView(R.id.rg)
    RadioGroup rg;
    @BindView(R.id.et_ddh)
    EditText etDdh;
    @BindView(R.id.ll_ddh)
    AutoLinearLayout llDdh;
    @BindView(R.id.rb_bg_zq)
    RadioButton rbBgZq;
    @BindView(R.id.rb_bg_yj)
    RadioButton rbBgYj;
    @BindView(R.id.rg_bg)
    RadioGroup rgBg;
    @BindView(R.id.tv_xzdz)
    TextView tvXzdz;
    @BindView(R.id.tv_xm)
    TextView tvXm;
    @BindView(R.id.tv_lxdh)
    TextView tvLxdh;
    @BindView(R.id.tv_yjdz)
    TextView tvYjdz;
    @BindView(R.id.ll_yj_father)
    AutoLinearLayout llYjFather;
    @BindView(R.id.btn_send)
    Button btnSend;
    @BindView(R.id.tv_ywtbh)
    TextView tvYwtbh;
    @BindView(R.id.et_bgfs)
    TextView etBgfs;
    @BindView(R.id.iv_wtd)
    ImageView ivWtd;


    List<PipeBean> listpipe = new ArrayList<>();
    OptionsPickerView pvFenLei, pvFs;
    private SimpleDateFormat format;
    private String PHOTO_FILE_NAME;
    private StringBuffer sb = new StringBuffer();
    private BottomMenuDialog mButtomMenuDialog;
    private File dir;
    private boolean isFirstIn = true;//记录是否是刚进入页面
    JcDialog.Builde builde;
    List<MaterialBean> listmaterial = new ArrayList<>();
    List<String> name = new ArrayList<>();
    List<FsBean> list1 = new ArrayList<>();
    List<String> lvname = new ArrayList<>();


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pipe);
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        initdata();
        initfelei();
        initfs();
    }

    private void initdata() {

        dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/PhotoPickTemp");
        if (!dir.exists()) {
            dir.mkdirs();
        }

        format = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.CHINA);

        tvTopTitleDrawer.setText(getIntent().getStringExtra("name"));
        tvSearchTopDrawer.setVisibility(View.INVISIBLE);
        tvJllb.setText("塑料管材");

        listpipe.add(new PipeBean("塑料管材", "1"));
        listpipe.add(new PipeBean("塑料管件", "2"));

        for (int i = 0; i < listpipe.size(); i++) {
            name.add(listpipe.get(i).getName());
        }


        list1.add(new FsBean("1份  ¥0", "1"));
        list1.add(new FsBean("2份  ¥10", "2"));
        list1.add(new FsBean("3份  ¥20", "3"));
        list1.add(new FsBean("4份  ¥30", "4"));
        list1.add(new FsBean("5份  ¥40", "5"));
        list1.add(new FsBean("6份  ¥50", "6"));
        list1.add(new FsBean("7份  ¥60", "7"));
        list1.add(new FsBean("8份  ¥70", "8"));
        list1.add(new FsBean("9份  ¥80", "9"));
        list1.add(new FsBean("10份  ¥90", "10"));

        for (int i = 0; i < list1.size(); i++) {
            lvname.add(list1.get(i).getName());
        }


        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, WtdwBeanUtils.listEName(GreendaoUtils.getDaoSession(PipeActivity.this, "wtdw.db")));
        commissionedEtWtdw.setAdapter(adapter);


        //委托人
        ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, WtrBeanUtils.listEName(GreendaoUtils.getDaoSession(PipeActivity.this, "wtr.db")));
        etWtr.setAdapter(adapter2);

        //委托人电话
        ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, WtrPhoneBeanUtils.listEName(GreendaoUtils.getDaoSession(PipeActivity.this, "wtrdh.db")));
        etWtrdh.setAdapter(adapter3);

        //工程名称
        ArrayAdapter<String> adapter4 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, GcmcBeanUtils.listEName(GreendaoUtils.getDaoSession(PipeActivity.this, "gcmc.db")));
        commissionedEtGcmc.setAdapter(adapter4);

        //施工部位
        ArrayAdapter<String> adapter5 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, SgbwBeanUtils.listEName(GreendaoUtils.getDaoSession(PipeActivity.this, "sgbw.db")));
        etSgbw.setAdapter(adapter5);

        //抽样单位
        ArrayAdapter<String> adapter6 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, CydwBeanUtils.listEName(GreendaoUtils.getDaoSession(PipeActivity.this, "cydw.db")));
        etCydw.setAdapter(adapter6);

        //抽样人
        ArrayAdapter<String> adapter7 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, CyrBeanUtils.listEName(GreendaoUtils.getDaoSession(PipeActivity.this, "cyr.db")));
        etCyr.setAdapter(adapter7);

        //见证单位
        ArrayAdapter<String> adapter8 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, JzdwBeanUtils.listEName(GreendaoUtils.getDaoSession(PipeActivity.this, "jzdw.db")));
        etJzdw.setAdapter(adapter8);

        //见证人
        ArrayAdapter<String> adapter9 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, JzrBeanUtils.listEName(GreendaoUtils.getDaoSession(PipeActivity.this, "jzr.db")));
        etJzr.setAdapter(adapter9);

        Callphone();
    }


    @OnClick({R.id.back, R.id.tv_jllb, R.id.btn_send, R.id.et_slgc_jcxm, R.id.et_slgj_jcxm,
            R.id.rb_zq, R.id.rb_yj, R.id.rb_bg_zq, R.id.rb_bg_yj, R.id.iv_wtd,
            R.id.tv_xzdz, R.id.et_bgfs})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.tv_jllb:
                pvFenLei.show();
                break;
            case R.id.btn_send:
                Toast.makeText(this, "保存", Toast.LENGTH_SHORT).show();
                WtdwBeanUtils.insertdata(commissionedEtWtdw.getText().toString());
                WtrBeanUtils.insertdata(etWtr.getText().toString());
                WtrPhoneBeanUtils.insertdata(etWtrdh.getText().toString());
                SgbwBeanUtils.insertdata(etSgbw.getText().toString());
                GcmcBeanUtils.insertdata(commissionedEtGcmc.getText().toString());
                CydwBeanUtils.insertdata(etCydw.getText().toString());
                CyrBeanUtils.insertdata(etCyr.getText().toString());
                JzdwBeanUtils.insertdata(etJzdw.getText().toString());
                JzrBeanUtils.insertdata(etJzr.getText().toString());
                finish();
                break;

            case R.id.rb_zq://样品送达方式 自送
                llDdh.setVisibility(View.GONE);
                etDdh.setText("");
                break;
            case R.id.rb_yj://邮寄
                llDdh.setVisibility(View.VISIBLE);
                break;
            case R.id.rb_bg_zq://报告发放方式 自取
                tvXzdz.setVisibility(View.GONE);
                llYjFather.setVisibility(View.GONE);
                tvXm.setText("");
                tvLxdh.setText("");
                tvYjdz.setText("");
                break;
            case R.id.rb_bg_yj:
                tvXzdz.setVisibility(View.VISIBLE);
                break;
            case R.id.tv_xzdz://选择地址
                Intent toaddress = new Intent(PipeActivity.this, AddressManagerActivity.class);
                toaddress.putExtra("finish", "yes");
                startActivity(toaddress);
                break;
            case R.id.et_slgc_jcxm:
                if (etSlgcJyyj.getText().toString().equals("")) {
                    builde.create().show();
                } else {
                    Intent tojcxm = new Intent(this, ChoiceActivity.class);
                    startActivity(tojcxm);
                    sb.setLength(0);
                }
                break;
            case R.id.et_slgj_jcxm:
                if (etSlgjYjbz.getText().toString().equals("")) {
                    builde.create().show();
                } else {
                    Intent tojcxm = new Intent(this, ChoiceActivity.class);
                    startActivity(tojcxm);
                    sb.setLength(0);
                }
                break;
            case R.id.iv_wtd:
                showDialog2(view, getTakePhoto());
                break;
            case R.id.et_bgfs:
                pvFs.show();
                break;
        }
    }


    //品种分类
    private void initfelei() {
        /**
         * @description
         *
         * 注意事项：
         * 自定义布局中，id为 optionspicker 或者 timepicker 的布局以及其子控件必须要有，否则会报空指针。
         * 具体可参考demo 里面的两个自定义layout布局。
         */

        pvFenLei = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {

                String tx = listpipe.get(options1).getName();
                tvJllb.setText(tx);

                switch (listpipe.get(options1).getId()) {
                    case "1":
                        llSlgcFather.setVisibility(View.VISIBLE);
                        llSlgjFather.setVisibility(View.GONE);
                        initclear();
                        break;
                    case "2":
                        llSlgcFather.setVisibility(View.GONE);
                        llSlgjFather.setVisibility(View.VISIBLE);
                        initclear();
                        break;
                }


            }
        }).setLayoutRes(R.layout.material_item, new CustomListener() {
            @Override
            public void customLayout(View v) {
                final TextView tvSubmit = (TextView) v.findViewById(R.id.tv_finish);
                TextView ivCancel = (TextView) v.findViewById(R.id.iv_cancel);
                tvSubmit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pvFenLei.returnData();
                        pvFenLei.dismiss();

                    }
                });

                ivCancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pvFenLei.dismiss();
                    }
                });
            }
        })
                .isDialog(false)
                .build();

        pvFenLei.setPicker(name);//添加数据
    }

    private void initclear() {
        etSlgcScdw.setText("");
        etSlgcCpmc.setText("");
        etSlgcJyyj.setText("");
        etSlgcGgxh.setText("");
        etSlgcDbpl.setText("");
        etSlgcZlzms.setText("");
        etSlgcSb.setText("");
        etSlgcLysl.setText("");
        etSlgcJcxm.setText("");

        etSlgjGgxh.setText("");
        etSlgjSjmc.setText("");
        etSlgjCjmc.setText("");
        etSlgjSb.setText("");
        etSlgjZlzmsh.setText("");
        etSlgjYjbz.setText("");
        etSlgjDbpl.setText("");
        etSlgjLysl.setText("");
        etSlgjJcxm.setText("");
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void XXl(List<MultipleBean> multiplist) {
        int price = 0;
        for (int i = 0; i < multiplist.size(); i++) {
            sb.append(multiplist.get(i).getName() + ",");
            price += multiplist.get(i).getPrice();
        }
        etFsjctyZj.setText("¥" + price);
        if (tvJllb.getText().toString().equals("塑料管材")) {
            etSlgcJcxm.setText(sb.toString().substring(0, sb.length() - 1));
        } else if (tvJllb.getText().toString().equals("塑料管件")) {
            etSlgjJcxm.setText(sb.toString().substring(0, sb.length() - 1));
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void XXX(AddressEventBean messageEvent) {
        if (messageEvent.getId().equals("address")) {
            tvXzdz.setVisibility(View.GONE);
            llYjFather.setVisibility(View.VISIBLE);
            tvXm.setText(messageEvent.getName());
            tvLxdh.setText(messageEvent.getPhone());
            tvYjdz.setText(messageEvent.getAddress());
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);

    }

    /**
     * 选择相册照片或者拍照
     */
    private void showDialog2(View view, final TakePhoto takePhoto) {
        mButtomMenuDialog = new BottomMenuDialog.Builder(this)
                .setShadow(true)
                .addMenu("从手机相册选择", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mButtomMenuDialog.dismiss();
                        selectPhoto(takePhoto);
                    }
                }).addMenu("拍照", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mButtomMenuDialog.dismiss();
                        PHOTO_FILE_NAME = format.format(new Date()) + ".jpg";//指定拍摄图片时 返回的文件名
                        File photo = new File(dir, PHOTO_FILE_NAME);
                        Uri uri = Uri.fromFile(photo);
                        Intent intent2 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//拍摄图片
                        intent2.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
                        intent2.putExtra(MediaStore.EXTRA_OUTPUT, uri);
                        startActivityForResult(intent2, 201);
                    }
                }).setCancelListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        mButtomMenuDialog.dismiss();
                    }
                })
                .create();
        mButtomMenuDialog.show();
    }

    /**
     * 选择本地图片的照片
     */
    private void selectPhoto(TakePhoto takePhoto) {
        File file = new File(Environment.getExternalStorageDirectory(), "/temp/" + System.currentTimeMillis() + ".jpg");
        if (!file.getParentFile().exists()) file.getParentFile().mkdirs();
        Uri imageUri = Uri.fromFile(file);
        configCompress(takePhoto);
        configTakePhotoOption(takePhoto);
        takePhoto.onPickMultiple(1);
    }

    private void configCompress(TakePhoto takePhoto) {
        CompressConfig config;
        config = new CompressConfig.Builder()
                .setMaxSize(200 * 1024)
                .create();

        takePhoto.onEnableCompress(config, true);
    }

    private void configTakePhotoOption(TakePhoto takePhoto) {
        TakePhotoOptions.Builder builder = new TakePhotoOptions.Builder();
        builder.setWithOwnGallery(true);
        builder.setCorrectImage(true);
        takePhoto.setTakePhotoOptions(builder.create());

    }


    /**
     * 选择照片、拍摄视频或者拍摄照片的返回结果
     *
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /**
         * 通过相机拍照并发送
         * */
        if (requestCode == 201) {
            if (resultCode == RESULT_OK) {
                isFirstIn = false;
                File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/PhotoPickTemp/" + PHOTO_FILE_NAME);
                Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);//刷新系统媒体库
                scanIntent.setData(Uri.fromFile(new File(file.getAbsolutePath())));
                sendBroadcast(scanIntent);//发送广播 刷新当前拍摄的图片 添加到系统媒体库
                int angle = BitmapUtils.readPictureDegree(file.getAbsolutePath());
                Bitmap bitmap = BitmapUtils.compressImage(angle, BitmapUtils.decodeUri(PipeActivity.this, Uri.fromFile(new File(file.getAbsolutePath())), 720, 1280), file.getAbsolutePath());
                ImageItem takePhoto = new ImageItem();
                takePhoto.setBitmap(bitmap);
                takePhoto.setImagePath(file.getAbsolutePath());
                if (Bimp.tempSelectBitmap.size() > 0)
                    Bimp.tempSelectBitmap.clear();

                Bimp.tempSelectBitmap.add(takePhoto);

                if (Bimp.tempSelectBitmap.size() > 0) {
                    ivWtd.setImageBitmap(Bimp.tempSelectBitmap.get(0).getBitmap());
                } else {
                    ivWtd.setImageResource(R.mipmap.a_dajiahao);
                }
            } else {
                if (isFirstIn) {
                    finish();
                }
            }
        }
    }

    @Override
    public void takeSuccess(TResult result) {
        super.takeSuccess(result);
        isFirstIn = false;
        showImg(result.getImages());
    }

    private void showImg(ArrayList<TImage> images) {
        if (Bimp.tempSelectBitmap.size() > 0)
            Bimp.tempSelectBitmap.clear();
        for (int i = 0; i < images.size(); i++) {
            ImageItem takePhoto = new ImageItem();
            takePhoto.setBitmap(BitmapUtils.decodeUri(PipeActivity.this, Uri.fromFile(new File(images.get(i).getCompressPath())), 720, 1280));
            takePhoto.setImagePath(images.get(i).getCompressPath());
            Bimp.tempSelectBitmap.add(takePhoto);
        }
        if (Bimp.tempSelectBitmap.size() > 0) {
            ivWtd.setImageBitmap(Bimp.tempSelectBitmap.get(0).getBitmap());
        } else {
            ivWtd.setImageResource(R.mipmap.a_dajiahao);
        }
    }


    private void Callphone() {
        builde = new JcDialog.Builde(this);
        builde.setCloseListener(new DialogInterface.OnClickListener() {//确定
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                Intent intent = new Intent(Intent.ACTION_CALL);
                Uri data = Uri.parse("tel:" + "02223382753");
                intent.setData(data);
                startActivity(intent);

            }
        });
        builde.setConfireListener(new DialogInterface.OnClickListener() {//取消
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
    }

    private void initfs() {
        pvFs = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {

                String tx = list1.get(options1).getName();
                etBgfs.setText(tx);

            }
        }).setLayoutRes(R.layout.material_item, new CustomListener() {
            @Override
            public void customLayout(View v) {
                final TextView tvSubmit = (TextView) v.findViewById(R.id.tv_finish);
                TextView ivCancel = (TextView) v.findViewById(R.id.iv_cancel);
                tvSubmit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pvFs.returnData();
                        pvFs.dismiss();

                    }
                });

                ivCancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pvFs.dismiss();
                    }
                });
            }
        })
                .isDialog(false)
                .build();

        pvFs.setPicker(lvname);//添加数据
    }
}
